package com.china08.yxyapi.api.manage.sch.platform.website.setting;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.sws.SwsSettingLinks;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.SwsSettingLinksRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class SwsSettingLinkListController extends YxyApiBaseController {

    @Autowired
    SwsSettingLinksRepository swsSettingLinksRepository;

    // 修改学校信息
    @ApiOperation(value = "修改学校信息")
    @RequestMapping(value = "/api_yw/manage/sch/platform/website/setting/link/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(HttpServletRequest request, HttpServletResponse response, @RequestBody(required = false) ReqModel reqModel) {

        List<RespModel> returnList = new ArrayList<RespModel>();

        String schoolId = getProfile(request, response).getSchoolId();
        List<SwsSettingLinks> settingLinksList = swsSettingLinksRepository.findBySchoolIdOrderByOrderNumAsc(schoolId);
        for (SwsSettingLinks swsSettingLinks : settingLinksList) {
            RespModel respModel = new RespModel();
            respModel.id = swsSettingLinks.getId();
            respModel.linkName = swsSettingLinks.getLinkName();
            respModel.linkUrl = swsSettingLinks.getLinkUrl();
            respModel.orderNum = swsSettingLinks.getOrderNum();
            returnList.add(respModel);
        }
        return returnList;
    }

    protected static class ReqModel extends YxyApiReqModel {

    }

    protected static class RespModel extends YxyApiRespModel {
        public String id;
        public String linkName;
        public String linkUrl;
        public Integer orderNum;
    }
}
